box gadget: Add a way to allocate in reverse
authorMatthias Clasen <mclasen@redhat.com>
Fri, 4 Mar 2016 02:24:20 +0000 (21:24 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 4 Mar 2016 02:28:51 +0000 (21:28 -0500)
This is needed to preserve expected allocation behavior
in rtl mode.

gtk/gtkboxgadget.c
gtk/gtkboxgadgetprivate.h

index 2380236500fd497740d2b2b4e9207b7b652d8d47..6533b6e77a597736ba43bb7a39f8a2a6c293b4a2 100644 (file)
@@ -40,6 +40,7 @@ struct _GtkBoxGadgetPrivate {
 
   guint draw_focus : 1;
   guint draw_reverse : 1;
+  guint allocate_reverse : 1;
 };
 
 typedef gboolean (* ComputeExpandFunc) (GObject *object, GtkOrientation orientation);
@@ -390,12 +391,18 @@ gtk_box_gadget_allocate (GtkCssGadget        *gadget,
     {
       gtk_box_gadget_distribute (GTK_BOX_GADGET (gadget), allocation->height, allocation->width, sizes);
 
+      if (priv->allocate_reverse)
+        child_allocation.x = allocation->x + allocation->width;
+
       for (i = 0; i < priv->children->len; i++)
         {
-          GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, i);
-          child_allocation.width = sizes[i].minimum_size;
+          guint idx = priv->allocate_reverse ? priv->children->len - 1 - i : i;
+          GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, idx);
+          child_allocation.width = sizes[idx].minimum_size;
           child_allocation.height = allocation->height;
           child_allocation.y = allocation->y;
+          if (priv->allocate_reverse)
+            child_allocation.x -= child_allocation.width;
 
           child_align = gtk_box_gadget_child_get_align (GTK_BOX_GADGET (gadget), child);
           gtk_box_gadget_allocate_child (child->object,
@@ -410,19 +417,26 @@ gtk_box_gadget_allocate (GtkCssGadget        *gadget,
           else
             gdk_rectangle_union (out_clip, &child_clip, out_clip);
 
-          child_allocation.x += sizes[i].minimum_size;
+          if (!priv->allocate_reverse)
+            child_allocation.x += sizes[idx].minimum_size;
         }
     }
   else
     {
       gtk_box_gadget_distribute (GTK_BOX_GADGET (gadget), allocation->width, allocation->height, sizes);
 
+      if (priv->allocate_reverse)
+        child_allocation.y = allocation->y + allocation->height;
+
       for (i = 0 ; i < priv->children->len; i++)
         {
-          GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, i);
-          child_allocation.height = sizes[i].minimum_size;
+          guint idx = priv->allocate_reverse ? priv->children->len - 1 - i : i;
+          GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, idx);
+          child_allocation.height = sizes[idx].minimum_size;
           child_allocation.width = allocation->width;
           child_allocation.x = allocation->x;
+          if (priv->allocate_reverse)
+            child_allocation.y -= child_allocation.height;
 
           child_align = gtk_box_gadget_child_get_align (GTK_BOX_GADGET (gadget), child);
           gtk_box_gadget_allocate_child (child->object,
@@ -437,7 +451,8 @@ gtk_box_gadget_allocate (GtkCssGadget        *gadget,
           else
             gdk_rectangle_union (out_clip, &child_clip, out_clip);
 
-          child_allocation.y += sizes[i].minimum_size;
+          if (!priv->allocate_reverse)
+            child_allocation.y += sizes[idx].minimum_size;
         }
     }
 }
@@ -571,6 +586,15 @@ gtk_box_gadget_set_draw_reverse (GtkBoxGadget *gadget,
   priv->draw_reverse = draw_reverse;
 }
 
+void
+gtk_box_gadget_set_allocate_reverse (GtkBoxGadget *gadget,
+                                     gboolean      allocate_reverse)
+{
+  GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
+
+  priv->allocate_reverse = allocate_reverse;
+}
+
 static GtkCssNode *
 get_css_node (GObject *child)
 {
index c970a3be490d7464c0f023eee03cd839f4149939..008fd1671b68883f73d679a99aa3302a111e8a81 100644 (file)
@@ -60,6 +60,8 @@ void                    gtk_box_gadget_set_draw_focus           (GtkBoxGadget
                                                                  gboolean                draw_focus);
 void                    gtk_box_gadget_set_draw_reverse         (GtkBoxGadget           *gadget,
                                                                  gboolean                draw_reverse);
+void                    gtk_box_gadget_set_allocate_reverse     (GtkBoxGadget           *gadget,
+                                                                 gboolean                allocate_reverse);
 
 void                    gtk_box_gadget_insert_widget            (GtkBoxGadget           *gadget,
                                                                  int                     pos,